#include "cScrollCamera.h"

cScrollCamera::cScrollCamera(void){
	MinDistanceX=300;
	MinDistanceY=50;
}

cScrollCamera::~cScrollCamera(void){
}
void cScrollCamera::Show(){
	cScrollCamera::Show(0);
}

void cScrollCamera::Show(int dir){
	float newSpeed;
	if(PhysicalObject->GetPosX()<GetPosX()+MinDistanceX){
		//SetPosX(PhysicalObject->GetPosX()-MinDistanceX);
		newSpeed=PhysicalObject->GetPosX()-MinDistanceX-GetPosX();
		SetSpeedX(newSpeed);
		SetDirectionX(1);
	}else if(PhysicalObject->GetPosX()>GetPosX()+GetWidth()-MinDistanceX){
		//SetPosX(PhysicalObject->GetPosX()-GetWidth()+MinDistanceX);
		newSpeed=PhysicalObject->GetPosX()-GetWidth()+MinDistanceX-GetPosX();
		SetSpeedX(newSpeed);
		SetDirectionX(1);
	}else{
		SetDirectionX(dir);
	}

	if(PhysicalObject->GetPosY()<GetPosY()+MinDistanceY){
		//SetPosY(PhysicalObject->GetPosY()-MinDistanceY);
		newSpeed=PhysicalObject->GetPosY()-MinDistanceY-GetPosY();
		SetSpeedY(newSpeed);		
		SetDirectionY(1);
	}else if(PhysicalObject->GetPosY()>GetPosY()+GetHeight()-MinDistanceY){
		//SetPosY(PhysicalObject->GetPosY()-GetHeight()+MinDistanceY);
		newSpeed=PhysicalObject->GetPosY()-GetHeight()+MinDistanceY-GetPosY();
		SetSpeedY(newSpeed);
		SetDirectionY(1);
	}else{
		SetDirectionY(0);
	}
	cCamera::Show();

    //glTranslatef(-GetPosX(),-GetPosY(), 0);
}

void cScrollCamera::Init(cPhysicalVisibleObject* objToChase, int Width, int Height, float SpeedX,
                                                float SpeedY, int PosX, int PosY){
	cCamera::Init(Width, Height, SpeedX, SpeedY, PosX, PosY);
	PhysicalObject=objToChase;
}